part of '../repository.dart';

const _kAppearanceSettingsDataThemeModeKey = 'theme_mode';
const _kAppearanceSettingsDataLightThemePrimaryColorKey = 'light_theme_primary_color';
const _kAppearanceSettingsDataDarkThemePrimaryColorKey = 'dark_theme_primary_color';

class _AppearanceSettingsDataDto extends Equatable {
  const _AppearanceSettingsDataDto._internal({
    required this.themeModeDto,
    required this.lightThemePrimaryColorDto,
    required this.darkThemePrimaryColorDto,
  });

  final _ThemeModeDto themeModeDto;
  final _LightThemePrimaryColorDto lightThemePrimaryColorDto;
  final _DarkThemePrimaryColorDto darkThemePrimaryColorDto;

  @override
  List<Object?> get props {
    return [
      themeModeDto,
      lightThemePrimaryColorDto,
      darkThemePrimaryColorDto,
    ];
  }

  factory _AppearanceSettingsDataDto.fromJson(Map<String, dynamic> json) {
    final themeModeDto = _ThemeModeDto.fromString(json[_kAppearanceSettingsDataThemeModeKey]);

    final lightThemePrimaryColorDto = _LightThemePrimaryColorDto.fromColorValue(
        json[_kAppearanceSettingsDataLightThemePrimaryColorKey]);

    final darkThemePrimaryColorDto = _DarkThemePrimaryColorDto.fromColorValue(
        json[_kAppearanceSettingsDataDarkThemePrimaryColorKey]);

    return _AppearanceSettingsDataDto._internal(
      themeModeDto: themeModeDto,
      lightThemePrimaryColorDto: lightThemePrimaryColorDto,
      darkThemePrimaryColorDto: darkThemePrimaryColorDto,
    );
  }

  factory _AppearanceSettingsDataDto.fromEntity(AppearanceSettingsData appearanceSettings) {
    final themeModeDto = _ThemeModeDto.fromEntity(appearanceSettings.themeMode);

    final lightThemePrimaryColorDto =
        _LightThemePrimaryColorDto.fromEntity(appearanceSettings.lightThemePrimaryColor);

    final darkThemePrimaryColorDto =
        _DarkThemePrimaryColorDto.fromEntity(appearanceSettings.darkThemePrimaryColor);

    return _AppearanceSettingsDataDto._internal(
      themeModeDto: themeModeDto,
      lightThemePrimaryColorDto: lightThemePrimaryColorDto,
      darkThemePrimaryColorDto: darkThemePrimaryColorDto,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      _kAppearanceSettingsDataThemeModeKey: themeModeDto.toString(),
      _kAppearanceSettingsDataLightThemePrimaryColorKey: lightThemePrimaryColorDto.toColorValue(),
      _kAppearanceSettingsDataDarkThemePrimaryColorKey: darkThemePrimaryColorDto.toColorValue(),
    };
  }

  AppearanceSettingsData toEntity() {
    return AppearanceSettingsData(
      themeMode: themeModeDto.toEntity(),
      lightThemePrimaryColor: lightThemePrimaryColorDto.toEntity(),
      darkThemePrimaryColor: darkThemePrimaryColorDto.toEntity(),
    );
  }
}
